from typing import List

class Solution:
    def maxProduct(self, nums: List[int]) -> int:
        if not nums:
            return 0
        
        n = len(nums)
        # 当前最大值
        current_max = nums[0]
        # 当前最小值
        current_min = nums[0]
        # 全局最大值
        global_max = nums[0]
        
        for i in range(1, n):
            # 保存前一个最大值
            prev_max = current_max
            # 当前最大值是三种情况中的最大值
            current_max = max(nums[i], prev_max * nums[i], current_min * nums[i])
            # 当前最小值是三种情况中的最小值
            current_min = min(nums[i], prev_max * nums[i], current_min * nums[i])
            # 更新全局最大值
            global_max = max(global_max, current_max)
        
        return global_max    